#include <bits/stdc++.h>
using namespace std;
int l, a[10010];
int main()
{
	int n, x, y;
	cin >> l >> n;
	int minn = 9999, maxn = -9999;
	for(int i = 1; i <= n; i++){
		cin >> x >> y;
		if(y == 1)
		{
			minn = min(minn, l + 1 - x);
			maxn = max(maxn, l + 1 - x);
		}
		if(y == -1)
		{
			minn = min(minn, x);
			maxn = max(maxn, x);
			minn = min(maxn, minn);
		}
	}
	cout << minn << " " << maxn;
	return 0;
}